package net.Stratus.ImageDumper;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class IOHelper {
	private File root;
	private boolean loaded;
	
	public IOHelper(String directory){
		root = new File(directory); 
		root.mkdirs();
		loaded = (root.exists()  && root.isDirectory() && root.canWrite());
	}

	public boolean isLoaded() {
		return loaded;
	}
	
	public static String fileToString(File file) {
		StringBuilder sb = new StringBuilder();
		try {
			FileInputStream fis = new FileInputStream(file);
			DataInputStream in = new DataInputStream(fis);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			
			int read;
			char[] buffer = new char[1024];
			while ((read = br.read(buffer)) != -1)   {
				sb.append(buffer, 0, read);
			}
			
			br.close();
			in.close();
			fis.close();
		} catch (IOException e) {
		}
		return sb.toString();
	}
}
